package com.exercise.utils;/**
 * Created by kete on 2017-05-11.
 */

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.util.StringUtils;

import java.text.DateFormat;
import java.text.ParseException;

/**
 * 作者：kete
 * 创建时间：2017-05-11 13:56
 * 功能描述：
 * 版本：
 */
public class EbsCustomDateEditor extends CustomDateEditor {

    public EbsCustomDateEditor(DateFormat dateFormat, boolean allowEmpty) {
        super(dateFormat, allowEmpty);
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {

        if (!StringUtils.hasText(text)) {
            setValue(null);
        } else {
            try {
                setValue(DateUtils.parseDate(text, "yyyy","yyyy-MM","yyyy-MM-dd","yyyy-MM-dd HH:mm","yyyy-MM-dd HH:mm:ss"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

    }
}
